//
//  LGMedicineManageController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/10/9.
//  用药管理

#import "LGMedicineManageController.h"
#import "LGMedicineListViewController.h"
#import "LGMedicineRecordController.h"
#import "LGAddMedicineController.h"
#import "LGRecipeMedicineAddCell.h"
@interface LGMedicineManageController ()<LGBottomButtonDelegate>
/**   */
@property (nonatomic , strong)LGMedicineListViewController *currentVC;
/**   */
@property (nonatomic , strong)LGMedicineListViewController *stopVC;
/**   */
@property (nonatomic , strong)LGMedicineRecordController *recordVC;
/**   */
@property (nonatomic , strong)NSMutableArray *controllerArray;
/**   */
@property (nonatomic , strong)NSArray *titleArray;
/**   */
@property (nonatomic , strong)LGBottomButtonView *addButton;
@end

@implementation LGMedicineManageController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"药物管理";
    self.prescripid = (_prescripid && _prescripid.length>0)?self.prescripid:@"";
    self.tempPrescripid = (_tempPrescripid && _tempPrescripid.length>0)?self.tempPrescripid:@"";
    self.view.backgroundColor = [UIColor colorWithString:@"#F3F7F8"];
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(300))];
    topView.backgroundColor = kNavBgColor;
    [self.view addSubview:topView];
    [self.view addSubview:self.addButton];
    self.titleArray = @[@"在用药品",@"停用药品",@"用药统计"];
    [self addChildViewController:self.currentVC];
    [self addChildViewController:self.stopVC];
    [self addChildViewController:self.recordVC];
    [self.controllerArray addObject:self.currentVC];
    [self.controllerArray addObject:self.stopVC];
    [self.controllerArray addObject:self.recordVC];
    self.scrollView.backgroundColor = [UIColor clearColor];
    self.titleColorNormal = [UIColor colorWithString:@"#606266"];
    self.titleColorSelected = [UIColor colorWithString:kThemeColor];
    self.progressColor = [UIColor colorWithString:kThemeColor];
    self.menuView.backgroundColor = [UIColor clearColor];
    self.menuViewStyle=WMMenuViewStyleLine;
    self.titleFontName = @"STHeitiTC-Medium";
    self.titleSizeSelected = 16;
    self.titleSizeNormal = 14;
    self.progressWidth = viewPix(13);
    self.progressHeight = 3;
    self.progressViewBottomSpace = 0;
    self.progressViewCornerRadius = 2;
    self.selectIndex = 0;
    [self reloadData];
    self.scrollView.backgroundColor = [UIColor clearColor];
}

//添加用药
-(void)bottomButtonTouched{
    LGAddMedicineController *controller = [[LGAddMedicineController alloc] init];
    controller.tempPrescripid = self.tempPrescripid;
    controller.patientid = self.patientid;
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark
#pragma mark ====> WMPageControllerDelegate
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titleArray.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titleArray[index];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    return self.controllerArray[index];
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    return Screen_W/3.0;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, 0, Screen_W, viewPix(44));
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    return CGRectMake(0, viewPix(44), Screen_W, Screen_H-topBarHeight-viewPix(44)-viewPix(65)-bottomSafeBarHeight/4.0);
}

- (void)pageController:(WMPageController *)pageController willEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    NSInteger index = [info[@"index"] integerValue];
    self.addButton.hidden = (index<2)?NO:YES;
//    LGBaseViewController *controller = (LGBaseViewController *)viewController;
//    [controller requestData];
//    NSLog(@">>>>>willEnterView>>>%@",viewController.title);
}

- (void)pageController:(WMPageController *)pageController didEnterViewController:(__kindof UIViewController *)viewController withInfo:(NSDictionary *)info{
    NSInteger index = [info[@"index"] integerValue];
    self.addButton.hidden = (index<2)?NO:YES;
    NSLog(@">>>>>didEnterView>>>%@",viewController.title);
}


-(NSMutableArray *)controllerArray{
    if(!_controllerArray){
        _controllerArray = [NSMutableArray array];
    }
    return _controllerArray;
}

-(LGMedicineListViewController *)currentVC{
    if(!_currentVC){
        _currentVC = [[LGMedicineListViewController alloc] init];
        _currentVC.action = @"/doctor/Sportsprescription.MedicinePrescription/initPreadd";
        _currentVC.paramaDic = @{@"patient_id":self.patientid,@"prescription_id":self.prescripid,@"temp_prescription_id":self.tempPrescripid};
        _currentVC.prescripid = self.prescripid;
        _currentVC.tempPrescripid = self.tempPrescripid;
        _currentVC.patientid = self.patientid;
    }
    return _currentVC;
}

-(LGMedicineListViewController *)stopVC{
    if(!_stopVC){
        _stopVC = [[LGMedicineListViewController alloc] init];
        _stopVC.action = @"/doctor/Sportsprescription.MedicinePrescription/stopPre";
        _stopVC.paramaDic = @{@"patient_id":self.patientid};
        _stopVC.prescripid = self.prescripid;
        _stopVC.tempPrescripid = self.tempPrescripid;
        _stopVC.patientid = self.patientid;
    }
    return _stopVC;
}

-(LGMedicineRecordController *)recordVC{
    if(!_recordVC){
        _recordVC = [[LGMedicineRecordController alloc] init];
        _recordVC.patientid = self.patientid;
    }
    return _recordVC;
}

-(LGBottomButtonView *)addButton{
    if(!_addButton){
        _addButton = [[LGBottomButtonView alloc] initWithTitle:@"添加用药" color:kThemeColor type:LGBottomButtonTypeBack frame:CGRectMake(0, Screen_H-topBarHeight-viewPix(65)-bottomSafeBarHeight/4.0, Screen_W, viewPix(65)+bottomSafeBarHeight/4.0)];
        _addButton.delegate = self;
    }
    return _addButton;
}


@end
